﻿using System;
namespace Producers.Rr.Xtee.Riik.Ee.Producer.Rr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="RRSydameTukseResponseType", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(RRSydameTukseResponseType))]
    public class RRSydameTukseResponseTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IRRSydameTukseResponseType clazz;
        
        public RRSydameTukseResponseTypeSerializer(IRRSydameTukseResponseType clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("seire_valjund1");
            if (clazz.SeireValjund1!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.SeireValjund1))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : SeireValjund1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("seire_valjund2");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "double");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDouble(((double)(clazz.SeireValjund2))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("Veakood");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.Veakood))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("Veatekst");
            if (clazz.Veatekst!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Veatekst))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Veatekst");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="seire_valjund1") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RRSydameTukseResponseType>seire_valjund1");
                }
                clazz.SeireValjund1 = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("seire_valjund1")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RRSydameTukseResponseType>seire_valjund1", Reader.LocalName);
            }
            if (Reader.LocalName=="seire_valjund2") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RRSydameTukseResponseType>seire_valjund2");
                }
                clazz.SeireValjund2 = new global::Xtee.Core.Schema.XsdDouble(Reader.ReadElementString("seire_valjund2")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RRSydameTukseResponseType>seire_valjund2", Reader.LocalName);
            }
            if (Reader.LocalName=="Veakood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RRSydameTukseResponseType>Veakood");
                }
                clazz.Veakood = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("Veakood")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RRSydameTukseResponseType>Veakood", Reader.LocalName);
            }
            if (Reader.LocalName=="Veatekst") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RRSydameTukseResponseType>Veatekst");
                }
                clazz.Veatekst = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Veatekst")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RRSydameTukseResponseType>Veatekst", Reader.LocalName);
            }
        }
    }
}
